import { reqCartList,reqDeleteCartById } from "@/api"

export default {
    state: {
        cartList: []
    },
    mutations: {
        GETCARTLIST(state, cartList) {
            state.cartList = cartList
        }
    },
    actions: {
        async getCartList({ commit }) {
            let res = await reqCartList();
            if (res.code == 200) {
                commit("GETCARTLIST", res.data);

            }
        },
        async deleteCartListBySkuId({commit},skuId){
            let res=await reqDeleteCartById(skuId)
            console.log(commit)
            console.log(res)
            if(res.code==200){
                return "ok"
            }else{
                return Promise.reject(new Error('faile'));
            }
        }
    },
    getters: {
        cartList(state) {
            return state.cartList || {}
        }
    }

}